package com.ruoyi.jiajia.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.JiajiaUserCoupon;
import com.ruoyi.system.service.IJiajiaUserCouponService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 个人优惠券Controller
 * 
 * @author knd
 * @date 2021-10-13
 */
@Controller
@RequestMapping("/jiajia/userCoupon")
public class JiajiaUserCouponController extends BaseController
{
    private String prefix = "jiajia/userCoupon";

    @Autowired
    private IJiajiaUserCouponService jiajiaUserCouponService;

    @RequiresPermissions("jiajia:userCoupon:view")
    @GetMapping()
    public String userCoupon()
    {
        return prefix + "/userCoupon";
    }

    /**
     * 查询个人优惠券列表
     */
    @RequiresPermissions("jiajia:userCoupon:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(JiajiaUserCoupon jiajiaUserCoupon)
    {
        startPage();
        List<JiajiaUserCoupon> list = jiajiaUserCouponService.selectJiajiaUserCouponList(jiajiaUserCoupon);
        return getDataTable(list);
    }

    /**
     * 导出个人优惠券列表
     */
    @RequiresPermissions("jiajia:userCoupon:export")
    @Log(title = "个人优惠券", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(JiajiaUserCoupon jiajiaUserCoupon)
    {
        List<JiajiaUserCoupon> list = jiajiaUserCouponService.selectJiajiaUserCouponList(jiajiaUserCoupon);
        ExcelUtil<JiajiaUserCoupon> util = new ExcelUtil<JiajiaUserCoupon>(JiajiaUserCoupon.class);
        return util.exportExcel(list, "个人优惠券数据");
    }

    /**
     * 新增个人优惠券
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存个人优惠券
     */
    @RequiresPermissions("jiajia:userCoupon:add")
    @Log(title = "个人优惠券", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(JiajiaUserCoupon jiajiaUserCoupon)
    {
        return toAjax(jiajiaUserCouponService.insertJiajiaUserCoupon(jiajiaUserCoupon));
    }

    /**
     * 修改个人优惠券
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        JiajiaUserCoupon jiajiaUserCoupon = jiajiaUserCouponService.selectJiajiaUserCouponById(id);
        mmap.put("jiajiaUserCoupon", jiajiaUserCoupon);
        return prefix + "/edit";
    }

    /**
     * 修改保存个人优惠券
     */
    @RequiresPermissions("jiajia:userCoupon:edit")
    @Log(title = "个人优惠券", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(JiajiaUserCoupon jiajiaUserCoupon)
    {
        return toAjax(jiajiaUserCouponService.updateJiajiaUserCoupon(jiajiaUserCoupon));
    }

    /**
     * 删除个人优惠券
     */
    @RequiresPermissions("jiajia:userCoupon:remove")
    @Log(title = "个人优惠券", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(jiajiaUserCouponService.deleteJiajiaUserCouponByIds(ids));
    }
}
